package DataBase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBHelper {
	private static final String driver="com.mysql.cj.jdbc.Driver";
	private static final String url="jdbc:mysql://localhost:3306/shaohui";
	private static final String user="root";
	private static final String password="521125";
	private static Connection conn=null;
	static {
		try {
			Class.forName(driver);
		} catch (Exception e) {
			 e.printStackTrace();
		}
	}
	public static Connection getConnection() throws SQLException {
		if(conn==null) {
			conn=DriverManager.getConnection(url, user, password);
			return conn;
		}
		return conn;		
	}
	public static void refeaseConnection(PreparedStatement ps,Connection cnn) throws SQLException {
		if(conn!=null) {
			ps.executeLargeUpdate();
			ps.close();
			conn.close();
		}	
	}
}
